﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Pro.DataServiceInterface;
using Pro.Web.Models;
using Pro.Models;

namespace Pro.Web.Controllers
{
    public class HomeController : Controller
    {
        private readonly IContactService _contactService;

        public HomeController(IContactService contactService)
        {
            _contactService = contactService;
        }

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "联系我们.";
            var model = new AddContactViewModel();
            return View(model);
        }

        [HttpPost]
        public ActionResult Contact(AddContactViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }
            var contact = new Contact
            {
                QQ = model.QQ,
                Username = model.Username,
                Subject = model.Subject,
                Body = model.Body
            };
            _contactService.Add(contact);

            return RedirectToAction("Index");
        }
    }
}